package CAS.AtomicInteger;

import java.util.concurrent.atomic.AtomicInteger;

public class AtomicIntegerDemo {
    static AtomicInteger atomicInteger = new AtomicInteger();

    static class Demo implements Runnable{
        @Override
        public void run() {
            for (int i = 0; i < 100; i++) {
                atomicInteger.incrementAndGet();
            }
        }
    }

    /*
        CAS, UnSafe类
     */
    public static void main(String[] args) throws InterruptedException {
        for (int i = 0; i < 100; i++) {
            Thread thread = new Thread(new Demo());
            thread.start();
            thread.join();
        }
        System.out.println(atomicInteger.get());// 10000
    }
}
